﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace SAHCPIMS_final
{
    public partial class SEARCH : Form
    {
        public int addMemberFlag;
        public string UpName;
        public int familyNumber;
        public int familyNumberSearched = 0;

        public System.Collections.ArrayList info = new System.Collections.ArrayList();
        public System.Collections.Generic.List<int> head = new System.Collections.Generic.List<int>();
        public System.Collections.Generic.List<string> famMemFirstName = new System.Collections.Generic.List<string>();
        public System.Collections.Generic.List<string> famMemMiddleName = new System.Collections.Generic.List<string>();
        public System.Collections.Generic.List<string> famMemLastName = new System.Collections.Generic.List<string>();
        public System.Collections.Generic.List<string> bday = new System.Collections.Generic.List<string>();
        public System.Collections.Generic.List<string> checkup = new System.Collections.Generic.List<string>();
        public System.Collections.Generic.List<int> weight = new System.Collections.Generic.List<int>();
        public System.Collections.ArrayList ops = new System.Collections.ArrayList();
        public int clicked = 0, counter2;
        int x, y;
        Label inf;
        LinkLabel ophandler;
        int counter = 0;
        int famNumberGlobal;
        string checkUp;

        public string homeEmpName;
        public int homeEmpNum;

        public SEARCH()
        {
            InitializeComponent();
        }

        private void SEARCH_Load(object sender, EventArgs e)
        {
            this.empNumLabel.Text = homeEmpNum.ToString();
            this.employeeLabel.Text = homeEmpName;
        }

        private void backButton_Click(object sender, EventArgs e)
        {
            HOME home = new HOME();
            home.homeEmpName = homeEmpName;
            home.homeEmpNum = homeEmpNum;
            home.Visible = true;
            this.Visible = false;
        }

        private void logOutButton_Click(object sender, EventArgs e)
        {
            LOGIN logout = new LOGIN();
            logout.Visible = true;
            this.Visible = false;
        }

        private void searchbutton_Click(object sender, EventArgs e)
        {
                panel2.Controls.Clear();

                string searchString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=..\\SAHCPIMS_database.mdb";
                OleDbConnection conn = new OleDbConnection(searchString);
                DataSet ds = new DataSet();

                conn.Open();
                OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * from Family", conn);
                adapter.Fill(ds);
                conn.Close();

                DataTable dt = ds.Tables[0];

                int temp, i = 0;
                counter = 0;
                clicked++;
                counter2 = 0;

                x = 100;
                y = 50;
                temp = x;
                foreach (DataRow dr in dt.Rows)
                {
                    x = temp;
                    if (textBox1.Text == "") {
                        inf = new Label();
                        inf.Text = "Family Number:   " + (dr["FamilyNum"]).ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "famNum";
                        inf.Location = new Point(x, y);
                        this.panel2.Controls.Add(inf);
                        head.Add(int.Parse((dr["FamilyNum"]).ToString()));

                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        inf.Text = "Family Head:   " + (dr["Firstname"]).ToString() + " " + (dr["Middlename"]).ToString() + " " + (dr["LastName"]).ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "famHead";
                        this.panel2.Controls.Add(inf);

                        ophandler = new LinkLabel();
                        ophandler.AutoSize = true;
                        ophandler.Location = new Point(x + (6 * inf.Text.Length), y);
                        ophandler.Text = "Add Member";
                        ophandler.Name = "addmemberLink" + counter2.ToString();
                        ophandler.BackColor = Color.Transparent;
                        this.panel2.Controls.Add(ophandler);
                        ophandler.Click += new EventHandler(addMember_Click);

                        x += 20;
                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["Birthday"].ToString()[3] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 8); }
                        else if (dr["Birthday"].ToString()[4] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 9); }
                        else if (dr["Birthday"].ToString()[5] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "bday";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        inf.Text = "Address:   " + (dr["Address"]).ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "address";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        i++;
                        counter2++;
                        checkMembers(int.Parse(dr["FamilyNum"].ToString()));

                    }
                    else if ((textBox1.Text.ToLower() == (dr["LastName"].ToString().ToLower())))
                    {

                        inf = new Label();
                        inf.Text = "Family Number:   " + (dr["FamilyNum"]).ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "famNum";
                        inf.Location = new Point(x, y);
                        this.panel2.Controls.Add(inf);
                        head.Add(int.Parse((dr["FamilyNum"]).ToString()));

                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        inf.Text = "Family Head:   " + (dr["Firstname"]).ToString() + " " + (dr["Middlename"]).ToString() + " " + (dr["LastName"]).ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "famHead";
                        this.panel2.Controls.Add(inf);

                        ophandler = new LinkLabel();
                        ophandler.AutoSize = true;
                        ophandler.Location = new Point(x + (6 * inf.Text.Length), y);
                        ophandler.Text = "Add Member";
                        ophandler.Name = "addmemberLink" + counter2.ToString();
                        ophandler.BackColor = Color.Transparent;
                        this.panel2.Controls.Add(ophandler);
                        ophandler.Click += new EventHandler(addMember_Click);

                        x += 20;
                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["Birthday"].ToString()[3] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 8); }
                        else if (dr["Birthday"].ToString()[4] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 9); }
                        else if (dr["Birthday"].ToString()[5] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "bday";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        inf.Text = "Address:   " + (dr["Address"]).ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "address";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        i++;
                        counter2++;
                        checkMembers(int.Parse(dr["FamilyNum"].ToString()));

                    }


                    else if (textBox1.Text.ToLower() == ((dr["FamilyNum"].ToString().ToLower())))
                    {

                        inf = new Label();
                        inf.Text = "Family Number:   " + (dr["FamilyNum"]).ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "famNum";
                        inf.Location = new Point(x, y);
                        this.panel2.Controls.Add(inf);
                        head.Add(int.Parse((dr["FamilyNum"]).ToString()));
                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        inf.Text = "Family Head:   " + (dr["Firstname"]).ToString() + " " + (dr["Middlename"]).ToString() + " " + (dr["LastName"]).ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "famHead";
                        this.panel2.Controls.Add(inf);


                        ophandler = new LinkLabel();
                        ophandler.AutoSize = true;
                        ophandler.Location = new Point(x + (6 * inf.Text.Length), y);
                        ophandler.Text = "Add Member";
                        ophandler.Name = "addMemberLink" + counter2.ToString();
                        ophandler.BackColor = Color.Transparent;
                        this.panel2.Controls.Add(ophandler);
                        ophandler.Click += new EventHandler(addMember_Click);

                        ophandler = new LinkLabel();
                        ophandler.AutoSize = true;
                        ophandler.Location = new Point(x + (10 * inf.Text.Length), y);
                        ophandler.Text = "View Members";
                        ophandler.Name = "viewmemberLink" + counter2.ToString();
                        ophandler.BackColor = Color.Transparent;
                        this.panel2.Controls.Add(ophandler);
                        ophandler.Click += new EventHandler(viewMember_Click);

                        x += 20;
                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["Birthday"].ToString()[3] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 8); }
                        else if (dr["Birthday"].ToString()[4] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 9); }
                        else if (dr["Birthday"].ToString()[5] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "bday";
                        this.panel2.Controls.Add(inf);
                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        inf.Text = "Address:   " + (dr["Address"]).ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "address";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        i++;
                        counter2++;
                        checkMembers(int.Parse(dr["FamilyNum"].ToString()));
                    }

                    /*****************************************************************************************/
                    // Substring Search
                    // by Nikko Santillan
                    else
                    {
                        if ((dr["LastName"].ToString().ToLower().StartsWith(textBox1.Text.ToLower())))
                        {


                            inf = new Label();
                            inf.Text = "Family Number:   " + (dr["FamilyNum"]).ToString();
                            inf.BackColor = Color.Transparent;
                            inf.Name = "famNum";
                            inf.Location = new Point(temp, y);
                            this.panel2.Controls.Add(inf);
                            head.Add(int.Parse((dr["FamilyNum"]).ToString()));

                            y += 25;

                            inf = new Label();
                            inf.AutoSize = true;
                            inf.Location = new Point(temp, y);
                            inf.Text = "Family Head:   " + (dr["Firstname"]).ToString() + " " + (dr["Middlename"]).ToString() + " " + (dr["LastName"]).ToString();
                            inf.BackColor = Color.Transparent;
                            inf.Name = "famHead";
                            this.panel2.Controls.Add(inf);

                            ophandler = new LinkLabel();
                            ophandler.AutoSize = true;
                            ophandler.Location = new Point(x + (6 * inf.Text.Length), y);
                            ophandler.Text = "Add Member";
                            ophandler.Name = "addMemberLink" + counter.ToString();
                            ophandler.BackColor = Color.Transparent;
                            this.panel2.Controls.Add(ophandler);
                            ophandler.Click += new EventHandler(addMember_Click);

                            ophandler = new LinkLabel();
                            ophandler.AutoSize = true;
                            ophandler.Location = new Point(x + (10 * inf.Text.Length), y);
                            ophandler.Text = "View Members";
                            ophandler.Name = "viewLink" + counter.ToString();
                            ophandler.BackColor = Color.Transparent;
                            this.panel2.Controls.Add(ophandler);
                            ophandler.Click += new EventHandler(viewMember_Click);

                            x += 20;
                            y += 25;

                            counter++;
                            i++;
                        }

                        if ((dr["Firstname"].ToString().ToLower().StartsWith(textBox1.Text.ToLower())))
                        {

                            inf = new Label();
                            inf.Text = "Family Number:   " + (dr["FamilyNum"]).ToString();
                            inf.BackColor = Color.Transparent;
                            inf.Name = "famNum";
                            inf.Location = new Point(x, y);
                            this.panel2.Controls.Add(inf);
                            head.Add(int.Parse((dr["FamilyNum"]).ToString()));

                            y += 25;

                            inf = new Label();
                            inf.AutoSize = true;
                            inf.Location = new Point(temp, y);
                            inf.Text = "Family Head:   " + (dr["Firstname"]).ToString() + " " + (dr["Middlename"]).ToString() + " " + (dr["LastName"]).ToString();
                            inf.BackColor = Color.Transparent;
                            inf.Name = "famHead";
                            this.panel2.Controls.Add(inf);

                            ophandler = new LinkLabel();
                            ophandler.AutoSize = true;
                            ophandler.Location = new Point(x + (6 * inf.Text.Length), y);
                            ophandler.Text = "Add Member";
                            ophandler.Name = "addMemberLink" + counter.ToString();
                            ophandler.BackColor = Color.Transparent;
                            this.panel2.Controls.Add(ophandler);
                            ophandler.Click += new EventHandler(addMember_Click);

                            ophandler = new LinkLabel();
                            ophandler.AutoSize = true;
                            ophandler.Location = new Point(x + (10 * inf.Text.Length), y);
                            ophandler.Text = "View Members";
                            ophandler.Name = "editLink" + counter.ToString();
                            ophandler.BackColor = Color.Transparent;
                            this.panel2.Controls.Add(ophandler);
                            ophandler.Click += new EventHandler(viewMember_Click);


                            x += 20;
                            y += 25;

                            i++;
                            counter++;
                        }


                    }
                    //end of substring search
                    /********************************************************************************************/

                }

                if (i == 0)
                {
                    MessageBox.Show(textBox1.Text + " not Found. Please Try Again.");
                    textBox1.ResetText();
                }
         
        }

        /**************************************************************************************************/
        //edit Member
        //Edited by: Nikko Santillan
        public void editMember_Click(object sender, EventArgs e)
        {
            LinkLabel myLink = (LinkLabel)sender;
            int familyNumber;

            string famMemberFirstName;
            string famMemberMiddleName;
            string famMemberLastName;
            string birthday;
            string mom = "";
            string end = myLink.Name.Substring(myLink.Name.Length - 1, 1);
            int[] hd = head.ToArray();


            familyNumber = famNumberGlobal;
            checkUp = checkup[int.Parse(end) - 1];
            famMemberFirstName = famMemFirstName[int.Parse(end) - 1];
            famMemberLastName = famMemLastName[int.Parse(end) - 1];
            famMemberMiddleName = famMemMiddleName[int.Parse(end) - 1];
            birthday = bday[int.Parse(end) - 1];

            ADDCHECKUP ac = new ADDCHECKUP();
            ac.homeEmpName = homeEmpName;
            ac.homeEmpNum = homeEmpNum;

            ac.familyNum = familyNumber;
            ac.fname = famMemberFirstName;
            ac.mname = famMemberMiddleName;
            ac.lname = famMemberLastName;
            ac.bdate = birthday;

            ac.Visible = true;
            this.Visible = false;

        }

        public void viewMember_Click(object sender, EventArgs e)
        {
            LinkLabel myLink = (LinkLabel)sender;
            int familyNumber;
            string end = myLink.Name.Substring(myLink.Name.Length - 1, 1);
            int[] hd = head.ToArray();

            panel2.Controls.Clear();
            y = 50;

            familyNumber = head[(int.Parse(end))];
            checkMembers(familyNumber);
        }

        private void addMember_Click(object sender, EventArgs e)
        {

            LinkLabel myLink = (LinkLabel)sender;
            int familyNumber;

            string end = myLink.Name.Substring(myLink.Name.Length - 1, 1);
            int[] hd = head.ToArray();

            familyNumber = head[int.Parse(end)];

            ADDMEMBER addmember = new ADDMEMBER();

            addmember.familyNumber = familyNumber;
            addmember.homeEmpName = homeEmpName;
            addmember.homeEmpNum = homeEmpNum;
            addmember.Visible = true;
            this.Visible = false;
        }

        /**************************************************************************************************/
        private void viewMemberInfo_Click(object sender, EventArgs e)
        {

            panel2.Controls.Clear();

            LinkLabel myLink = (LinkLabel)sender;
            int familyNumber;
            int oldx;

            string famMemberFirstName;
            string famMemberMiddleName;
            string famMemberLastName;
            string birthday;
            string end = myLink.Name.Substring(myLink.Name.Length - 1, 1);
            int[] hd = head.ToArray();


            familyNumber = famNumberGlobal;
            checkUp = checkup[int.Parse(end) - 1];
            famMemberFirstName = famMemFirstName[int.Parse(end) - 1];
            famMemberLastName = famMemLastName[int.Parse(end) - 1];
            famMemberMiddleName = famMemMiddleName[int.Parse(end) - 1];
            birthday = bday[int.Parse(end) - 1];

            x = 100;
            y = 50;


            counter++;

            inf = new Label();
            inf.AutoSize = true;
            inf.Location = new Point(x, y);
            inf.Text = "Name:   " + famMemberFirstName + " " + famMemberMiddleName + " " + famMemberLastName;
            inf.BackColor = Color.Transparent;
            inf.Name = "memberName";
            this.panel2.Controls.Add(inf);

            x += 20;
            y += 25;

            inf = new Label();
            inf.AutoSize = true;
            inf.Location = new Point(x, y);
            if (birthday[3] == '/') { inf.Text = "Birthday:   " + birthday.Substring(0, 8); }
            else if (birthday[4] == '/') { inf.Text = "Birthday:   " + birthday.Substring(0, 9); }
            else if (birthday[5] == '/') { inf.Text = "Birthday:   " + birthday.Substring(0, 10); }
            inf.BackColor = Color.Transparent;
            inf.Name = "bday";
            this.panel2.Controls.Add(inf);

            y += 25;

            inf = new Label();
            inf.AutoSize = true;
            inf.Location = new Point(x, y);
            inf.Text = "Weight:   " + weight[int.Parse(end)].ToString() + " kg";
            inf.BackColor = Color.Transparent;
            inf.Name = "weight";
            this.panel2.Controls.Add(inf);

            y += 25;

            if (checkUp == "Prenatal")
            {

                string searchString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=..\\SAHCPIMS_database.mdb";
                OleDbConnection conn = new OleDbConnection(searchString);
                DataSet ds = new DataSet();

                conn.Open();
                OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * from Prenatal", conn);
                adapter.Fill(ds);
                conn.Close();

                oldx = x;
                DataTable dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    if ((int.Parse(dr["FamilyNum"].ToString()) == famNumberGlobal) && (dr["FirstName"].ToString() == famMemberFirstName))
                    {
                        x = oldx;
                        counter++;


                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["CheckUpDate"].ToString()[3] == '/') { inf.Text = "Check Up Date:   " + (dr["CheckUpDate"]).ToString().Substring(0, 8); }
                        else if (dr["CheckUpDate"].ToString()[4] == '/') { inf.Text = "Check Up Date:   " + (dr["CheckUpDate"]).ToString().Substring(0, 9); }
                        else if (dr["CheckUpDate"].ToString()[5] == '/') { inf.Text = "Check Up Date:   " + (dr["CheckUpDate"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "checkupdate";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["ExpectedDeliveryDate"].ToString()[3] == '/') { inf.Text = "Expected Delivery Date:   " + (dr["ExpectedDeliveryDate"]).ToString().Substring(0, 8); }
                        else if (dr["ExpectedDeliveryDate"].ToString()[4] == '/') { inf.Text = "Expected Delivery Date:   " + (dr["ExpectedDeliveryDate"]).ToString().Substring(0, 9); }
                        else if (dr["ExpectedDeliveryDate"].ToString()[5] == '/') { inf.Text = "Expected Delivery Date:   " + (dr["ExpectedDeliveryDate"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "expecteddate";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["LMP"].ToString()[3] == '/') { inf.Text = "LMP:   " + (dr["LMP"]).ToString().Substring(0, 8); }
                        else if (dr["LMP"].ToString()[4] == '/') { inf.Text = "LMP:   " + (dr["LMP"]).ToString().Substring(0, 9); }
                        else if (dr["LMP"].ToString()[5] == '/') { inf.Text = "LMP:   " + (dr["LMP"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "lmp";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        inf.Text = "Gravida: " + dr["Gravida"].ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "expecteddate";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        inf.Text = "Para: " + dr["Para"].ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "para";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                    }
                }


                searchString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=..\\SAHCPIMS_database.mdb";
                conn = new OleDbConnection(searchString);
                ds = new DataSet();

                conn.Open();
                adapter = new OleDbDataAdapter("SELECT * from ToxoidPrenatal", conn);
                adapter.Fill(ds);
                conn.Close();

                dt = ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {
                    if ((int.Parse(dr["FamilyNumber"].ToString()) == famNumberGlobal) && (dr["FirstName"].ToString() == famMemberFirstName))
                    {


                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["ToxoidDate"].ToString()[3] == '/') { inf.Text = "Toxoid:   " + (dr["ToxoidDate"]).ToString().Substring(0, 8); }
                        else if (dr["ToxoidDate"].ToString()[4] == '/') { inf.Text = "Toxoid:   " + (dr["ToxoidDate"]).ToString().Substring(0, 9); }
                        else if (dr["ToxoidDate"].ToString()[5] == '/') { inf.Text = "Toxoid:   " + (dr["ToxoidDate"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "toxoid";
                        this.panel2.Controls.Add(inf);

                        y += 25;
                    }
                }
            }

            if (checkUp == "Vaccine")
            {

                string searchString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=..\\SAHCPIMS_database.mdb";
                OleDbConnection conn = new OleDbConnection(searchString);
                DataSet ds = new DataSet();

                conn.Open();
                OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * from Vaccine", conn);
                adapter.Fill(ds);
                conn.Close();

                DataTable dt = ds.Tables[0];

                oldx = x;
                foreach (DataRow dr in dt.Rows)
                {
                    if ((int.Parse(dr["FamilyNum"].ToString()) == famNumberGlobal) && (dr["FirstName"].ToString() == famMemberFirstName))
                    {
                        x = oldx;
                        counter++;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        inf.Text = "Mother:" + dr["Mother"].ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "mother";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["CheckUpDate"].ToString()[3] == '/') { inf.Text = "Check Up Date:   " + (dr["CheckUpDate"]).ToString().Substring(0, 8); }
                        else if (dr["CheckUpDate"].ToString()[4] == '/') { inf.Text = "Check Up Date:   " + (dr["CheckUpDate"]).ToString().Substring(0, 9); }
                        else if (dr["CheckUpDate"].ToString()[5] == '/') { inf.Text = "Check Up Date:   " + (dr["CheckUpDate"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "checkupdate";
                        this.panel2.Controls.Add(inf);

                        y += 25;
                    }
                }


                searchString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=..\\SAHCPIMS_database.mdb";
                conn = new OleDbConnection(searchString);
                ds = new DataSet();

                conn.Open();
                adapter = new OleDbDataAdapter("SELECT * from NewBornScreening", conn);
                adapter.Fill(ds);
                conn.Close();

                dt = ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {
                    if ((int.Parse(dr["FamilyNum"].ToString()) == famNumberGlobal) && (dr["FirstName"].ToString() == famMemberFirstName))
                    {

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["NBSDate"].ToString()[3] == '/') { inf.Text = "New Born Screening Date:   " + (dr["NBSDate"]).ToString().Substring(0, 8); }
                        else if (dr["NBSDate"].ToString()[4] == '/') { inf.Text = "New Born Screening Date:   " + (dr["NBSDate"]).ToString().Substring(0, 9); }
                        else if (dr["NBSDate"].ToString()[5] == '/') { inf.Text = "New Born Screening Date:   " + (dr["NBSDate"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "nbsdate";
                        this.panel2.Controls.Add(inf);

                        y += 25;
                    }
                }


                searchString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=..\\SAHCPIMS_database.mdb";
                conn = new OleDbConnection(searchString);
                ds = new DataSet();

                conn.Open();
                adapter = new OleDbDataAdapter("SELECT * from Feeding", conn);
                adapter.Fill(ds);
                conn.Close();

                dt = ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {
                    if ((int.Parse(dr["FamilyNumber"].ToString()) == famNumberGlobal) && (dr["FirstName"].ToString() == famMemberFirstName))
                    {

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["CheckUpDate"].ToString()[3] == '/') { inf.Text = "Check Up Date:   " + (dr["CheckUpDate"]).ToString().Substring(0, 8); }
                        else if (dr["CheckUpDate"].ToString()[4] == '/') { inf.Text = "Check Up Date:   " + (dr["CheckUpDate"]).ToString().Substring(0, 9); }
                        else if (dr["CheckUpDate"].ToString()[5] == '/') { inf.Text = "Check Up Date:   " + (dr["CheckUpDate"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "checkupdate";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        inf.Text = "Feeding Type:" + dr["FeedingType"].ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "feedingtype";
                        this.panel2.Controls.Add(inf);

                        y += 25;

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        inf.Text = "Duration:" + dr["Duration"].ToString();
                        inf.BackColor = Color.Transparent;
                        inf.Name = "duration";
                        this.panel2.Controls.Add(inf);

                        y += 25;


                    }
                }


                searchString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=..\\SAHCPIMS_database.mdb";
                conn = new OleDbConnection(searchString);
                ds = new DataSet();

                conn.Open();
                adapter = new OleDbDataAdapter("SELECT * from DPT", conn);
                adapter.Fill(ds);
                conn.Close();

                dt = ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {
                    if ((int.Parse(dr["FamilyNum"].ToString()) == famNumberGlobal) && (dr["FirstName"].ToString() == famMemberFirstName))
                    {

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["DPT_Date"].ToString()[3] == '/') { inf.Text = "DPT Date:   " + (dr["DPT_Date"]).ToString().Substring(0, 8); }
                        else if (dr["DPT_Date"].ToString()[4] == '/') { inf.Text = "DPT Date:   " + (dr["DPT_Date"]).ToString().Substring(0, 9); }
                        else if (dr["DPT_Date"].ToString()[5] == '/') { inf.Text = "DPT Date:   " + (dr["DPT_Date"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "dptdate";
                        this.panel2.Controls.Add(inf);

                        y += 25;


                    }
                }



                searchString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=..\\SAHCPIMS_database.mdb";
                conn = new OleDbConnection(searchString);
                ds = new DataSet();

                conn.Open();
                adapter = new OleDbDataAdapter("SELECT * from BCG", conn);
                adapter.Fill(ds);
                conn.Close();

                dt = ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {
                    if ((int.Parse(dr["FamilyNumber"].ToString()) == famNumberGlobal) && (dr["FirstName"].ToString() == famMemberFirstName))
                    {

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["BCGDate"].ToString()[3] == '/') { inf.Text = "BCG Date:   " + (dr["BCGDate"]).ToString().Substring(0, 8); }
                        else if (dr["BCGDate"].ToString()[4] == '/') { inf.Text = "BCG Date:   " + (dr["BCGDate"]).ToString().Substring(0, 9); }
                        else if (dr["BCGDate"].ToString()[5] == '/') { inf.Text = "BCG Date:   " + (dr["BCGDate"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "bcgdate";
                        this.panel2.Controls.Add(inf);

                        y += 25;


                    }
                }




                searchString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=..\\SAHCPIMS_database.mdb";
                conn = new OleDbConnection(searchString);
                ds = new DataSet();

                conn.Open();
                adapter = new OleDbDataAdapter("SELECT * from Hepa", conn);
                adapter.Fill(ds);
                conn.Close();

                dt = ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {
                    if ((int.Parse(dr["FamilyNum"].ToString()) == famNumberGlobal) && (dr["FirstName"].ToString() == famMemberFirstName))
                    {

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["Hepa_Date"].ToString()[3] == '/') { inf.Text = "Hepa Date:   " + (dr["Hepa_Date"]).ToString().Substring(0, 8); }
                        else if (dr["Hepa_Date"].ToString()[4] == '/') { inf.Text = "Hepa Date:   " + (dr["Hepa_Date"]).ToString().Substring(0, 9); }
                        else if (dr["Hepa_Date"].ToString()[5] == '/') { inf.Text = "Hepa Date:   " + (dr["Hepa_Date"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "hepadate";
                        this.panel2.Controls.Add(inf);

                        y += 25;


                    }
                }




                searchString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=..\\SAHCPIMS_database.mdb";
                conn = new OleDbConnection(searchString);
                ds = new DataSet();

                conn.Open();
                adapter = new OleDbDataAdapter("SELECT * from ToxoidVaccine", conn);
                adapter.Fill(ds);
                conn.Close();

                dt = ds.Tables[0];

                foreach (DataRow dr in dt.Rows)
                {
                    if ((int.Parse(dr["FamilyNumber"].ToString()) == famNumberGlobal) && (dr["FirstName"].ToString() == famMemberFirstName))
                    {

                        inf = new Label();
                        inf.AutoSize = true;
                        inf.Location = new Point(x, y);
                        if (dr["ToxoidDate"].ToString()[3] == '/') { inf.Text = "Toxoid Date:   " + (dr["ToxoidDate"]).ToString().Substring(0, 8); }
                        else if (dr["ToxoidDate"].ToString()[4] == '/') { inf.Text = "Toxoid Date:   " + (dr["ToxoidDate"]).ToString().Substring(0, 9); }
                        else if (dr["ToxoidDate"].ToString()[5] == '/') { inf.Text = "Toxoid Date:   " + (dr["ToxoidDate"]).ToString().Substring(0, 10); }
                        inf.BackColor = Color.Transparent;
                        inf.Name = "toxoiddate";
                        this.panel2.Controls.Add(inf);

                        y += 25;


                    }
                }
            }

        }

        /*******************************************************************************************************************/

        private void checkMembers(int famNum)
        {
            int count = 0;
            int memberCounter = 0;
            counter = 0;
            string searchString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data source=..\\SAHCPIMS_database.mdb";
            OleDbConnection conn = new OleDbConnection(searchString);
            DataSet ds = new DataSet();

            conn.Open();
            OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * from FamilyMember", conn);
            adapter.Fill(ds);
            conn.Close();

            DataTable dt = ds.Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                if (int.Parse(dr["FamilyNum"].ToString()) == famNum)
                {
                    count++;
                }
            }
            if (count > 0)
            {
                inf = new Label();
                inf.AutoSize = true;
                inf.Location = new Point(x, y);
                inf.Text = "Member(s):";
                inf.BackColor = Color.Transparent;
                inf.Name = "memLabel";
                this.panel2.Controls.Add(inf);

                y += 25;
            }
            int oldx = x;
            foreach (DataRow dr in dt.Rows)
            {
                if (int.Parse(dr["FamilyNum"].ToString()) == famNum)
                {
                    famNumberGlobal = famNum;
                    x = oldx;
                    counter++;

                    inf = new Label();
                    inf.AutoSize = true;
                    inf.Location = new Point(x, y);
                    inf.Text = "Name:   " + (dr["Firstname"]).ToString() + " " + (dr["Middlename"]).ToString() + " " + (dr["LastName"]).ToString();
                    inf.BackColor = Color.Transparent;
                    inf.Name = "memberName";
                    this.panel2.Controls.Add(inf);
                    famMemFirstName.Add((dr["Firstname"]).ToString());
                    famMemMiddleName.Add((dr["Middlename"]).ToString());
                    famMemLastName.Add((dr["LastName"]).ToString());


                    ophandler = new LinkLabel();
                    ophandler.AutoSize = true;
                    ophandler.Location = new Point(x + (6 * inf.Text.Length), y);
                    ophandler.Text = "View Member Info";
                    ophandler.Name = "editLink" + counter.ToString();
                    ophandler.BackColor = Color.Transparent;
                    this.panel2.Controls.Add(ophandler);
                    ophandler.Click += new EventHandler(viewMemberInfo_Click);

                    ophandler = new LinkLabel();
                    ophandler.AutoSize = true;
                    ophandler.Location = new Point(x + (10 * inf.Text.Length), y);
                    ophandler.Text = "Add Checkup";
                    ophandler.Name = "addLink" + counter.ToString();
                    ophandler.BackColor = Color.Transparent;
                    this.panel2.Controls.Add(ophandler);
                    ophandler.Click += new EventHandler(editMember_Click);
                    checkup.Add((dr["CheckUp"]).ToString());

                    x += 20;
                    y += 25;

                    inf = new Label();
                    inf.AutoSize = true;
                    inf.Location = new Point(x, y);
                    if (dr["Birthday"].ToString()[3] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 8); }
                    else if (dr["Birthday"].ToString()[4] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 9); }
                    else if (dr["Birthday"].ToString()[5] == '/') { inf.Text = "Birthday:   " + (dr["Birthday"]).ToString().Substring(0, 10); }
                    inf.BackColor = Color.Transparent;
                    inf.Name = "bday";
                    this.panel2.Controls.Add(inf);
                    bday.Add((dr["Birthday"]).ToString());
                    y += 25;

                    inf = new Label();
                    inf.AutoSize = true;
                    inf.Location = new Point(x, y);
                    inf.Text = "Weight:   " + (dr["Weight"]).ToString() + " kg";
                    inf.BackColor = Color.Transparent;
                    inf.Name = "weight";
                    this.panel2.Controls.Add(inf);
                    weight.Add(int.Parse((dr["Weight"]).ToString()));

                    y += 25;

                    memberCounter++;
                }
            }

            if (memberCounter == 0)
            {
                x = oldx;
                inf = new Label();
                inf.AutoSize = true;
                inf.Location = new Point(x, y);
                inf.Text = "No Member Yet.";
                inf.BackColor = Color.Transparent;
                inf.Name = "weight";
                this.panel2.Controls.Add(inf);
                y += 25;

            }
        }
    }
}